<?php

namespace App\Http\Controllers;

use App\Common\HttpClient;
use App\Common\Logger;
use App\Common\Sql;
use App\Common\Tool;
use App\Logic\LoginLogic;
use Illuminate\Support\Facades\DB;

class Login extends Base
{
    public function logic()
    {
        if (!isset($this->param['user'])) {
            return $this->returnError(1, "手机号输入不能为空");
        }
        if (!isset($this->param['password'])) {
            return $this->returnError(2, "密码输入不能为空");
        }

        $user = strtolower($this->param['user']);
        $row  = Sql::select('t_player_info', [['phone_num', $user]]);
        if (count($row) == 0) {
            return $this->returnError(3, '您输入的手机账户不存在');
        } elseif (count($row) > 1) {
            Logger::instance()->error(Tool::getUri(), "{$user} repeat");
            return $this->returnError(4, "错误, 出现重复账户");
        }
        $passwd_md5 = md5($this->param['password']);
        if ($passwd_md5 != $row[0]['passwd_md5']) {
            return $this->returnError(5, '密码错误');
        }
        if ($row[0]['status'] == 0) {
            return $this->returnError(6, "对不起，您的账号被管理员禁号，如有疑问请联系客户");
        }
        $row[0]['type'] = 1;
        return $this->returnData(LoginLogic::instance()->postPosition($row[0]));
    }
}